import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by LiuChang on 2017/5/5.
 */
public class HttpClient {
    public static void main(String[] args) throws IOException {

        HttpPost request = new HttpPost("http://www.tuling123.com/openapi/api");
//        request.setHeader("Content-Type", "application/json");
        List<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("key", "996a7ca7038c435e9786c2b82be3419c"));
        params.add(new BasicNameValuePair("info", "abc"));

        UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(params);
        request.setEntity(urlEncodedFormEntity);

        HttpResponse response = HttpClients.createDefault().execute(request);

        String result = "";
        if (response.getStatusLine().getStatusCode() == 200) {
            result = EntityUtils.toString(response.getEntity(), "utf-8");
        }
        System.out.println(result);
    }
}

